package com.maben.vue_support.config;

import com.maben.vue_support.constant.YmlConstant;
import com.maben.vue_support.interceptor.LogInterceptor;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import javax.annotation.Resource;

/**
 * mvc配置
 **/
@Component
public class WebMvcConfig extends WebMvcConfigurationSupport {

        @Resource
        private YmlConstant ymlConstant;

    @Resource
    private LogInterceptor logInterceptor;

    @Override
    protected void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/login/");
        super.addViewControllers(registry);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //配置外部可访问文件路径
        registry.addResourceHandler("/export_file/**").addResourceLocations("file:" +ymlConstant.getExportFilePath());
        //静态资源映射
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        //添加knife4j
        registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(logInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(ymlConstant.getExcludePathPatterns());
        super.addInterceptors(registry);
    }


}